qui(
    function (require, exports, module) {
        window.EpgWeb = window.EpgWeb || {
            version: '1.0'
        };


// [步骤名称 操作结果] [entityId=节目Id][msg=任意消息][stepInfo={json对象，用于携带其它信息}][cost=步骤执行耗时，可选]
        EpgWeb.PingBack = {
            PARAM_TYPE:{
                append_submit:402,
                normal_submit:403
            },
            typeArr: ["create_video", "submit_format"],
            doFoldList: function (originalData) {
                var retValue = originalData;
                try {
                    var newData = JSON.parse(retValue);
                    if (newData.list != null) {
                        newData.list = JSON.parse(newData.list)
                        var newFold = [];
                        var nodeStart = -100;
                        var nodeEnd = -100;
                        var curIndex = 0;
                        $.each(newData.list, function (i, element) {
                            curIndex = element;
                            if (curIndex > nodeEnd + 1) {
                                if (nodeStart >= 0) {
                                    newFold.push({ start: nodeStart, end: nodeEnd});
                                }
                                nodeStart = curIndex;
                                nodeEnd = curIndex;
                            } else if (curIndex == nodeEnd + 1) {
                                nodeEnd = curIndex;
                            }
                        })
                        if (nodeEnd >= nodeStart) {
                            newFold.push({ start: nodeStart, end: nodeEnd});
                        }
                        newData.list = newFold;
                        retValue = JSON.stringify(newData);
                    }
                } catch (e) {
                    console.log("error", e);
                }
                return retValue
            },
            transFormatData: function (wrapData) {
                var ret = {};
                ret.success = wrapData.success;
                if (wrapData.success == true) {
                    ret.successLogExpression = "[" + wrapData.funcType + " success]";
                } else {
                    ret.failLogExpression = "[" + wrapData.funcType + " error]";
                }
                ret.detail = "[entityId=" + wrapData.programId + "][stepInfo=" + this.doFoldList(wrapData.sendData) + "][plusMsg=" + wrapData.plusMsg + "]";
                wrapData.sendData = null;
                ret.keyId = "" + wrapData.programId;
                ret.serverIp = "" + wrapData.serverIp;
                ret.relationData = [
                    {description: "奇谱", columnName: "programId", "columnValue": "" + wrapData.programId, "isQueryParam": "0", "isQueryList": "1"}
                ];
                ret.paramType = wrapData.paramType ?  wrapData.paramType:this.PARAM_TYPE.append_submit;
                return  ret
            },
            doExecute: function (wrapData, callback) {
                var testUrl = "http://xiu-test-monitor-dev001-cqdx.qiyi.virtual/monitor-api/pingback/flow";
                var onlineUrl = "http://monitor.live.qiyi.domain/monitor-api/pingback/flow";
                var paramsArr = [];
                var retData = this.transFormatData(wrapData);
                paramsArr.push({keyName: "business", value: "live2vod"});
                paramsArr.push({keyName: "paramType", value: retData.paramType })
                if (retData.success) {
                    paramsArr.push({keyName: "successLogExpression", value: retData.successLogExpression})
                } else {
                    paramsArr.push({keyName: "failLogExpression", value: retData.failLogExpression})
                }
                paramsArr.push({keyName: "sendTime", value: new Date().getTime() })
                paramsArr.push({keyName: "detail", value: retData.detail});
                paramsArr.push({keyName: "keyId", value: retData.keyId})
                paramsArr.push({keyName: "serverIp", value: retData.serverIp}) //
                paramsArr.push({keyName: "relationData", value: retData.relationData})
                paramsArr.push({keyName: "checkToken", value: md5("business=live2vod|F@(LhCw79plfWd3$83#530")})

                var sendData = {}
                $.each(paramsArr, function (index, element) {
                    if (element.value != null) {
                        sendData[element.keyName] = element.value;
                    }
                })

                for (var key in wrapData) {
                    if(wrapData[key] != null){
                        sendData[key] = wrapData[key];
                    }
                }
                var options = {
                    url: auth.dev() ? testUrl : onlineUrl,
                    dataType: 'json',
                    data: sendData,
                    type: "post",
                    success: function (data) {
                        if (callback != null) {
                            callback.call(this, data);
                        }
                    },
                    error: function (data) {
                        if (callback != null) {
                            callback.call(this, data);
                        }
                    }
                }
                EpgWeb.Dao.sendProxy(options)
            },
            doQuickSend: function (wrapData) {
                this.doExecute(wrapData, function (data) {
                    console.log(data);
                })
            }
        }
    }
);